//
//  MineViewController.m
//  USB_Reader
//
//  Created by xiaozao on 15/3/21.
//  Copyright (c) 2015年 Tony_Wang. All rights reserved.
//

#import "MineViewController.h"
#import "CDSideBarController.h"
#import "SDImageCache.h"
@interface MineViewController ()<CDSideBarControllerDelegate, NSFileManagerDelegate>
@property (nonatomic, retain) CDSideBarController *sideBar;
@property (nonatomic, retain) UIView *viewB;

@end

@implementation MineViewController

-(void)dealloc
{
    [_viewB release];
    [_sideBar release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 关灯模式
    self.viewB = [[UIView alloc] initWithFrame:self.view.bounds];
    self.viewB.userInteractionEnabled = NO;
    [[UIApplication sharedApplication].keyWindow addSubview:self.viewB];
    [_viewB release];
    
    //    NSDictionary *alert = @{};
    //    alert[@"title"]
    GUAAlertView *alert = [GUAAlertView alertViewWithTitle:@"了解一下我们吧"message:@"开发者:Tony & Why" buttonTitle:@"迫不及待了" buttonTouchedAction:^{
        
    } dismissAction:^{
        
    }];
    
    alert.tintColor = [UIColor blackColor];
    [self.view addSubview:alert];
    
    [alert show];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    
    CGFloat x = self.view.bounds.origin.x;
    CGFloat y = self.view.bounds.origin.y;
    
    CGFloat width = self.view.bounds.size.width;
    CGFloat height = self.view.bounds.size.height;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x+40, y+100, width/3+30, width/3+30)];
    
    label.backgroundColor = [UIColor colorFromHexCode:@"#00EE76"];
    label.layer.cornerRadius = width/6+15;
    label.clipsToBounds = YES;
    [self.view addSubview:label];
    label.layer.borderWidth = 2;
    label.text = @"We do";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont boldSystemFontOfSize:30];
    [label release];
    
    
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(x+220, y+100, width/4, width/4)];
    
    label1.backgroundColor = [UIColor colorFromHexCode:@"#00BFFF"];
    label1.layer.cornerRadius = width/8;
    label1.clipsToBounds = YES;
    [self.view addSubview:label1];
    label1.layer.borderWidth = 2;
    label1.text = @"Believe";
    label1.textAlignment = NSTextAlignmentCenter;
    label1.textColor = [UIColor whiteColor];
    label1.font = [UIFont boldSystemFontOfSize:22];
    
    [label1 release];
    
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(x+200, y+200, width/5, width/5)];
    label2.backgroundColor = [UIColor colorFromHexCode:@"#FF00FF"];
    label2.layer.cornerRadius = width/10;
    label2.clipsToBounds = YES;
    [self.view addSubview:label2];
    label2.layer.borderWidth = 2;
    
    label2.layer.borderWidth = 2;
    label2.text = @"You";
    label2.textAlignment = NSTextAlignmentCenter;
    label2.textColor = [UIColor whiteColor];
    label2.font = [UIFont boldSystemFontOfSize:20];
    
    [label2 release];
    
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(width/3+20, height/25, width/3, height/10)];
    label3.textColor = [UIColor blackColor];
    label3.text = @"About";
    label3.font = [UIFont boldSystemFontOfSize:30];
    [self.view addSubview:label3];
    
    [label3 release];
    

    
    
    
    UITextView *introdutionLabel = [[UITextView alloc] initWithFrame:CGRectMake(width/2-100, height/2+30, self.view.bounds.size.width/3+100, self.view.bounds.size.height/3)];
    introdutionLabel.clipsToBounds = YES;
    introdutionLabel.layer.cornerRadius = 20;
    introdutionLabel.layer.borderWidth = 2;
    
    introdutionLabel.backgroundColor = [UIColor colorFromHexCode:@"#D3D3D3"];
    
    introdutionLabel.textColor = [UIColor whiteColor];
    introdutionLabel.font = [UIFont boldSystemFontOfSize:15];
    introdutionLabel.textAlignment = 1;
    introdutionLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
    introdutionLabel.text = @"友情提示：这里可以滑动\n我们是一个做iOS的小团队，没有美工，没有UI设计师，一共就2人。\n有一天，我们突然想要做一个阅读器，唯一的要求就是简洁，方便，不仅能读文本，还能读照片，音乐，DPF...\n于是我们开始寻找灵感——打开App Store，遇到某个好的应用，我们就下载到手机上。打开App Store，遇到某个好的应用，我们就下载到手机上，然后试用...\n打开App Store，遇到某个好的应用，我们就下载到手机上，然后试用。终于，我们找到灵感了，开始设计，于是就有了这款APP，希望你们能喜欢";
    
    [self.view addSubview:introdutionLabel];
    introdutionLabel.editable = NO;
    [introdutionLabel release];
    
    
    
    // Do any additional setup after loading the view.
    
    NSArray *imageArr = @[[UIImage imageNamed:@"iconfont-yijianfankui.png"], [UIImage imageNamed:@"iconfont-yejian01.png"], [UIImage imageNamed:@"iconfont-lajiqingli.png"]];
    
    self.sideBar = [[CDSideBarController alloc] initWithImages:imageArr];
    self.sideBar.delegate = self;
    [_sideBar release];
    
    
    

    self.view.backgroundColor = [UIColor colorFromHexCode:@"#696969"];
    
}

#pragma 清理缓存 夜间模式 打个分
- (void)menuButtonClicked:(int)index
{
    if (index == 2) {
        //        NSString *strPath = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"/Library"] stringByAppendingString:@"/Caches"];
        //
        
        //        NSLog(@"清理缓存%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]);
        //        NSLog(@"%@", strPath);
        //
        //        NSError *error = nil;
        //
        //        NSFileManager *fileM = [NSFileManager defaultManager];
        //      [fileM changeCurrentDirectoryPath:[strPath stringByExpandingTildeInPath]];
        //
        //           NSLog(@"%@", strPath);
        //        [fileM removeItemAtPath:strPath error:&error];
        //           NSLog(@"%@", strPath);
        
        NSInteger cache = [[NSURLCache sharedURLCache] currentDiskUsage];
        CGFloat fCache = cache / 1024 / 1024;
        NSLog(@"*******%lf", fCache);
        
        NSString *str = [NSString stringWithFormat:@"已经帮您清除了%.2lfMB的垃圾", [[SDImageCache sharedImageCache] checkTmpSize]+fCache];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清理缓存" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        
        [alert show];
        [alert release];
        
        [[SDImageCache sharedImageCache] clearDisk];
       
        
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
        
    } else if (index == 1) {
        
        static NSInteger ret = 0;
        NSInteger retD = ret % 2;
        
        
        if (retD == 0) {
            self.viewB.backgroundColor = [UIColor blackColor];
            self.viewB.alpha = 0.4;
            
            
            //            ret++;
        }else if (retD == 1){
            self.viewB.backgroundColor = [UIColor blackColor];
            self.viewB.alpha = 0;
//            UIAlertView *noti = [[UIAlertView alloc] initWithTitle:@"友情提示" message:@"再点一下可以更亮" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//            [noti show];
//            [noti release];
            
            //            ret++;
        }
        NSLog(@"%lu", retD);
        ret++;
        
        
    } else if (index == 0) {
#pragma 打个分
        
//                NSString *str = [NSString stringWithFormat:
//                                 @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",547203890];
    
        GUAAlertView *alert1 = [GUAAlertView alertViewWithTitle:@"去微博提点意见吧"message:@"去还是不去" buttonTitle:@"去" buttonTouchedAction:^{
            
            NSString *str = [@"http://weibo.com/p/1005051864147595" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
            
        } dismissAction:^{
            
        }];
        
        alert1.tintColor = [UIColor blackColor];
        [self.view addSubview:alert1];
        
        [alert1 show];
        [alert1 release];
        
    }
}




- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.sideBar insertMenuButtonOnView:self.view atPosition:CGPointMake(self.view.frame.size.width - 70, 50)];
}



#pragma 清理缓存






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
